package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"time"
)

// MediaRecord holds the schema definition for the MediaRecord entity.
type MediaRecord struct {
	ent.Schema
}

// Fields of the MediaRecord.
func (MediaRecord) Fields() []ent.Field {
	return []ent.Field{
		field.String("title").
			NotEmpty().
			Comment("标题"),
		field.String("type").
			Comment("类型：电影/书/音乐"),
		field.String("status").
			Default("想看").
			Comment("状态：想看/已看"),
		field.Int32("rating").
			Optional().
			Min(0).
			Max(10).
			Comment("评分 0-10"),
		field.Text("note").
			Optional().
			Comment("备注"),
		field.Int64("creator_id").
			Comment("创建者ID"),
		field.Time("deleted_at").
			Optional().
			Nillable().
			Comment("软删除时间"),
		field.Time("created_at").
			Default(time.Now).
			Immutable().
			Comment("创建时间"),
		field.Time("updated_at").
			Default(time.Now).
			UpdateDefault(time.Now).
			Comment("更新时间"),
	}
}

// Edges of the MediaRecord.
func (MediaRecord) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("creator", User.Type).
			Ref("media_records").
			Field("creator_id").
			Unique().
			Required(),
	}
}
